<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /usr/include/boost/random/uniform_int_distribution.hpp</title>
  <link rel="stylesheet" type="text/css" href="../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../index.html">top level</a> - <a href="index.html">usr/include/boost/random</a> - uniform_int_distribution.hpp<span style="font-size: 80%;"> (source / <a href="uniform_int_distribution.hpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">29</td>
            <td class="headerCovTableEntryLo">0.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:25:26</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntryLo">0.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : /* boost random/uniform_int_distribution.hpp header file</a>
<span class="lineNum">       2 </span>            :  *
<span class="lineNum">       3 </span>            :  * Copyright Jens Maurer 2000-2001
<span class="lineNum">       4 </span>            :  * Copyright Steven Watanabe 2011
<span class="lineNum">       5 </span>            :  * Distributed under the Boost Software License, Version 1.0. (See
<span class="lineNum">       6 </span>            :  * accompanying file LICENSE_1_0.txt or copy at
<span class="lineNum">       7 </span>            :  * http://www.boost.org/LICENSE_1_0.txt)
<span class="lineNum">       8 </span>            :  *
<span class="lineNum">       9 </span>            :  * See http://www.boost.org for most recent version including documentation.
<span class="lineNum">      10 </span>            :  *
<span class="lineNum">      11 </span>            :  * $Id$
<span class="lineNum">      12 </span>            :  *
<span class="lineNum">      13 </span>            :  * Revision history
<span class="lineNum">      14 </span>            :  *  2001-04-08  added min&lt;max assertion (N. Becker)
<span class="lineNum">      15 </span>            :  *  2001-02-18  moved to individual header files
<span class="lineNum">      16 </span>            :  */
<span class="lineNum">      17 </span>            : 
<span class="lineNum">      18 </span>            : #ifndef BOOST_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP
<span class="lineNum">      19 </span>            : #define BOOST_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP
<span class="lineNum">      20 </span>            : 
<span class="lineNum">      21 </span>            : #include &lt;iosfwd&gt;
<span class="lineNum">      22 </span>            : #include &lt;ios&gt;
<span class="lineNum">      23 </span>            : #include &lt;istream&gt;
<span class="lineNum">      24 </span>            : #include &lt;boost/config.hpp&gt;
<span class="lineNum">      25 </span>            : #include &lt;boost/limits.hpp&gt;
<span class="lineNum">      26 </span>            : #include &lt;boost/assert.hpp&gt;
<span class="lineNum">      27 </span>            : #include &lt;boost/random/detail/config.hpp&gt;
<span class="lineNum">      28 </span>            : #include &lt;boost/random/detail/operators.hpp&gt;
<span class="lineNum">      29 </span>            : #include &lt;boost/random/detail/uniform_int_float.hpp&gt;
<span class="lineNum">      30 </span>            : #include &lt;boost/random/detail/signed_unsigned_tools.hpp&gt;
<span class="lineNum">      31 </span>            : #include &lt;boost/type_traits/make_unsigned.hpp&gt;
<span class="lineNum">      32 </span>            : #include &lt;boost/type_traits/is_integral.hpp&gt;
<span class="lineNum">      33 </span>            : #include &lt;boost/mpl/bool.hpp&gt;
<span class="lineNum">      34 </span>            : 
<span class="lineNum">      35 </span>            : namespace boost {
<span class="lineNum">      36 </span>            : namespace random {
<span class="lineNum">      37 </span>            : namespace detail {
<span class="lineNum">      38 </span>            :     
<span class="lineNum">      39 </span>            : 
<span class="lineNum">      40 </span>            : #ifdef BOOST_MSVC
<span class="lineNum">      41 </span>            : #pragma warning(push)
<span class="lineNum">      42 </span>            : // disable division by zero warning, since we can't
<span class="lineNum">      43 </span>            : // actually divide by zero.
<span class="lineNum">      44 </span>            : #pragma warning(disable:4723)
<span class="lineNum">      45 </span>            : #endif
<a name="46"><span class="lineNum">      46 </span>            : </a>
<span class="lineNum">      47 </span>            : template&lt;class Engine, class T&gt;
<span class="lineNum">      48 </span><span class="lineNoCov">          0 : T generate_uniform_int(</span>
<span class="lineNum">      49 </span>            :     Engine&amp; eng, T min_value, T max_value,
<span class="lineNum">      50 </span>            :     boost::mpl::true_ /** is_integral&lt;Engine::result_type&gt; */)
<span class="lineNum">      51 </span>            : {
<span class="lineNum">      52 </span>            :     typedef T result_type;
<span class="lineNum">      53 </span>            :     typedef typename make_unsigned&lt;T&gt;::type range_type;
<span class="lineNum">      54 </span>            :     typedef typename Engine::result_type base_result;
<span class="lineNum">      55 </span>            :     // ranges are always unsigned
<span class="lineNum">      56 </span>            :     typedef typename make_unsigned&lt;base_result&gt;::type base_unsigned;
<span class="lineNum">      57 </span>            :     const range_type range = random::detail::subtract&lt;result_type&gt;()(max_value, min_value);
<span class="lineNum">      58 </span>            :     const base_result bmin = (eng.min)();
<span class="lineNum">      59 </span>            :     const base_unsigned brange =
<span class="lineNum">      60 </span>            :       random::detail::subtract&lt;base_result&gt;()((eng.max)(), (eng.min)());
<span class="lineNum">      61 </span>            : 
<span class="lineNum">      62 </span><span class="lineNoCov">          0 :     if(range == 0) {</span>
<span class="lineNum">      63 </span>            :       return min_value;    
<span class="lineNum">      64 </span><span class="lineNoCov">          0 :     } else if(brange == range) {</span>
<span class="lineNum">      65 </span>            :       // this will probably never happen in real life
<span class="lineNum">      66 </span>            :       // basically nothing to do; just take care we don't overflow / underflow
<span class="lineNum">      67 </span><span class="lineNoCov">          0 :       base_unsigned v = random::detail::subtract&lt;base_result&gt;()(eng(), bmin);</span>
<span class="lineNum">      68 </span>            :       return random::detail::add&lt;base_unsigned, result_type&gt;()(v, min_value);
<span class="lineNum">      69 </span><span class="lineNoCov">          0 :     } else if(brange &lt; range) {</span>
<span class="lineNum">      70 </span>            :       // use rejection method to handle things like 0..3 --&gt; 0..4
<span class="lineNum">      71 </span>            :       for(;;) {
<span class="lineNum">      72 </span>            :         // concatenate several invocations of the base RNG
<span class="lineNum">      73 </span>            :         // take extra care to avoid overflows
<span class="lineNum">      74 </span>            : 
<span class="lineNum">      75 </span>            :         //  limit == floor((range+1)/(brange+1))
<span class="lineNum">      76 </span>            :         //  Therefore limit*(brange+1) &lt;= range+1
<span class="lineNum">      77 </span>            :         range_type limit;
<span class="lineNum">      78 </span><span class="lineNoCov">          0 :         if(range == (std::numeric_limits&lt;range_type&gt;::max)()) {</span>
<span class="lineNum">      79 </span><span class="lineNoCov">          0 :           limit = range/(range_type(brange)+1);</span>
<span class="lineNum">      80 </span><span class="lineNoCov">          0 :           if(range % (range_type(brange)+1) == range_type(brange))</span>
<span class="lineNum">      81 </span><span class="lineNoCov">          0 :             ++limit;</span>
<span class="lineNum">      82 </span>            :         } else {
<span class="lineNum">      83 </span><span class="lineNoCov">          0 :           limit = (range+1)/(range_type(brange)+1);</span>
<span class="lineNum">      84 </span>            :         }
<span class="lineNum">      85 </span>            : 
<span class="lineNum">      86 </span>            :         // We consider &quot;result&quot; as expressed to base (brange+1):
<span class="lineNum">      87 </span>            :         // For every power of (brange+1), we determine a random factor
<span class="lineNum">      88 </span>            :         range_type result = range_type(0);
<span class="lineNum">      89 </span>            :         range_type mult = range_type(1);
<span class="lineNum">      90 </span>            : 
<span class="lineNum">      91 </span>            :         // loop invariants:
<span class="lineNum">      92 </span>            :         //  result &lt; mult
<span class="lineNum">      93 </span>            :         //  mult &lt;= range
<span class="lineNum">      94 </span><span class="lineNoCov">          0 :         while(mult &lt;= limit) {</span>
<span class="lineNum">      95 </span>            :           // Postcondition: result &lt;= range, thus no overflow
<span class="lineNum">      96 </span>            :           //
<span class="lineNum">      97 </span>            :           // limit*(brange+1)&lt;=range+1                   def. of limit       (1)
<span class="lineNum">      98 </span>            :           // eng()-bmin&lt;=brange                          eng() post.         (2)
<span class="lineNum">      99 </span>            :           // and mult&lt;=limit.                            loop condition      (3)
<span class="lineNum">     100 </span>            :           // Therefore mult*(eng()-bmin+1)&lt;=range+1      by (1),(2),(3)      (4)
<span class="lineNum">     101 </span>            :           // Therefore mult*(eng()-bmin)+mult&lt;=range+1   rearranging (4)     (5)
<span class="lineNum">     102 </span>            :           // result&lt;mult                                 loop invariant      (6)
<span class="lineNum">     103 </span>            :           // Therefore result+mult*(eng()-bmin)&lt;range+1  by (5), (6)         (7)
<span class="lineNum">     104 </span>            :           //
<span class="lineNum">     105 </span>            :           // Postcondition: result &lt; mult*(brange+1)
<span class="lineNum">     106 </span>            :           //
<span class="lineNum">     107 </span>            :           // result&lt;mult                                 loop invariant      (1)
<span class="lineNum">     108 </span>            :           // eng()-bmin&lt;=brange                          eng() post.         (2)
<span class="lineNum">     109 </span>            :           // Therefore result+mult*(eng()-bmin) &lt;
<span class="lineNum">     110 </span>            :           //           mult+mult*(eng()-bmin)            by (1)              (3)
<span class="lineNum">     111 </span>            :           // Therefore result+(eng()-bmin)*mult &lt;
<span class="lineNum">     112 </span>            :           //           mult+mult*brange                  by (2), (3)         (4)
<span class="lineNum">     113 </span>            :           // Therefore result+(eng()-bmin)*mult &lt;
<span class="lineNum">     114 </span>            :           //           mult*(brange+1)                   by (4)
<span class="lineNum">     115 </span><span class="lineNoCov">          0 :           result += static_cast&lt;range_type&gt;(random::detail::subtract&lt;base_result&gt;()(eng(), bmin) * mult);</span>
<span class="lineNum">     116 </span>            : 
<span class="lineNum">     117 </span>            :           // equivalent to (mult * (brange+1)) == range+1, but avoids overflow.
<span class="lineNum">     118 </span><span class="lineNoCov">          0 :           if(mult * range_type(brange) == range - mult + 1) {</span>
<span class="lineNum">     119 </span>            :               // The destination range is an integer power of
<span class="lineNum">     120 </span>            :               // the generator's range.
<span class="lineNum">     121 </span><span class="lineNoCov">          0 :               return(result);</span>
<span class="lineNum">     122 </span>            :           }
<span class="lineNum">     123 </span>            : 
<span class="lineNum">     124 </span>            :           // Postcondition: mult &lt;= range
<span class="lineNum">     125 </span>            :           // 
<span class="lineNum">     126 </span>            :           // limit*(brange+1)&lt;=range+1                   def. of limit       (1)
<span class="lineNum">     127 </span>            :           // mult&lt;=limit                                 loop condition      (2)
<span class="lineNum">     128 </span>            :           // Therefore mult*(brange+1)&lt;=range+1          by (1), (2)         (3)
<span class="lineNum">     129 </span>            :           // mult*(brange+1)!=range+1                    preceding if        (4)
<span class="lineNum">     130 </span>            :           // Therefore mult*(brange+1)&lt;range+1           by (3), (4)         (5)
<span class="lineNum">     131 </span>            :           // 
<span class="lineNum">     132 </span>            :           // Postcondition: result &lt; mult
<span class="lineNum">     133 </span>            :           //
<span class="lineNum">     134 </span>            :           // See the second postcondition on the change to result. 
<span class="lineNum">     135 </span><span class="lineNoCov">          0 :           mult *= range_type(brange)+range_type(1);</span>
<span class="lineNum">     136 </span>            :         }
<span class="lineNum">     137 </span>            :         // loop postcondition: range/mult &lt; brange+1
<span class="lineNum">     138 </span>            :         //
<span class="lineNum">     139 </span>            :         // mult &gt; limit                                  loop condition      (1)
<span class="lineNum">     140 </span>            :         // Suppose range/mult &gt;= brange+1                Assumption          (2)
<span class="lineNum">     141 </span>            :         // range &gt;= mult*(brange+1)                      by (2)              (3)
<span class="lineNum">     142 </span>            :         // range+1 &gt; mult*(brange+1)                     by (3)              (4)
<span class="lineNum">     143 </span>            :         // range+1 &gt; (limit+1)*(brange+1)                by (1), (4)         (5)
<span class="lineNum">     144 </span>            :         // (range+1)/(brange+1) &gt; limit+1                by (5)              (6)
<span class="lineNum">     145 </span>            :         // limit &lt; floor((range+1)/(brange+1))           by (6)              (7)
<span class="lineNum">     146 </span>            :         // limit==floor((range+1)/(brange+1))            def. of limit       (8)
<span class="lineNum">     147 </span>            :         // not (2)                                       reductio            (9)
<span class="lineNum">     148 </span>            :         //
<span class="lineNum">     149 </span>            :         // loop postcondition: (range/mult)*mult+(mult-1) &gt;= range
<span class="lineNum">     150 </span>            :         //
<span class="lineNum">     151 </span>            :         // (range/mult)*mult + range%mult == range       identity            (1)
<span class="lineNum">     152 </span>            :         // range%mult &lt; mult                             def. of %           (2)
<span class="lineNum">     153 </span>            :         // (range/mult)*mult+mult &gt; range                by (1), (2)         (3)
<span class="lineNum">     154 </span>            :         // (range/mult)*mult+(mult-1) &gt;= range           by (3)              (4)
<span class="lineNum">     155 </span>            :         //
<span class="lineNum">     156 </span>            :         // Note that the maximum value of result at this point is (mult-1),
<span class="lineNum">     157 </span>            :         // so after this final step, we generate numbers that can be
<span class="lineNum">     158 </span>            :         // at least as large as range.  We have to really careful to avoid
<span class="lineNum">     159 </span>            :         // overflow in this final addition and in the rejection.  Anything
<span class="lineNum">     160 </span>            :         // that overflows is larger than range and can thus be rejected.
<span class="lineNum">     161 </span>            : 
<span class="lineNum">     162 </span>            :         // range/mult &lt; brange+1  -&gt; no endless loop
<span class="lineNum">     163 </span>            :         range_type result_increment =
<span class="lineNum">     164 </span><span class="lineNoCov">          0 :             generate_uniform_int(</span>
<span class="lineNum">     165 </span>            :                 eng,
<span class="lineNum">     166 </span>            :                 static_cast&lt;range_type&gt;(0),
<span class="lineNum">     167 </span>            :                 static_cast&lt;range_type&gt;(range/mult),
<span class="lineNum">     168 </span><span class="lineNoCov">          0 :                 boost::mpl::true_());</span>
<span class="lineNum">     169 </span><span class="lineNoCov">          0 :         if((std::numeric_limits&lt;range_type&gt;::max)() / mult &lt; result_increment) {</span>
<span class="lineNum">     170 </span>            :           // The multiplcation would overflow.  Reject immediately.
<span class="lineNum">     171 </span>            :           continue;
<span class="lineNum">     172 </span>            :         }
<span class="lineNum">     173 </span><span class="lineNoCov">          0 :         result_increment *= mult;</span>
<span class="lineNum">     174 </span>            :         // unsigned integers are guaranteed to wrap on overflow.
<span class="lineNum">     175 </span><span class="lineNoCov">          0 :         result += result_increment;</span>
<span class="lineNum">     176 </span><span class="lineNoCov">          0 :         if(result &lt; result_increment) {</span>
<span class="lineNum">     177 </span>            :           // The addition overflowed.  Reject.
<span class="lineNum">     178 </span>            :           continue;
<span class="lineNum">     179 </span>            :         }
<span class="lineNum">     180 </span><span class="lineNoCov">          0 :         if(result &gt; range) {</span>
<span class="lineNum">     181 </span>            :           // Too big.  Reject.
<span class="lineNum">     182 </span>            :           continue;
<span class="lineNum">     183 </span>            :         }
<span class="lineNum">     184 </span>            :         return random::detail::add&lt;range_type, result_type&gt;()(result, min_value);
<span class="lineNum">     185 </span>            :       }
<span class="lineNum">     186 </span>            :     } else {                   // brange &gt; range
<span class="lineNum">     187 </span>            :       base_unsigned bucket_size;
<span class="lineNum">     188 </span>            :       // it's safe to add 1 to range, as long as we cast it first,
<span class="lineNum">     189 </span>            :       // because we know that it is less than brange.  However,
<span class="lineNum">     190 </span>            :       // we do need to be careful not to cause overflow by adding 1
<span class="lineNum">     191 </span>            :       // to brange.
<span class="lineNum">     192 </span>            :       if(brange == (std::numeric_limits&lt;base_unsigned&gt;::max)()) {
<span class="lineNum">     193 </span><span class="lineNoCov">          0 :         bucket_size = brange / (static_cast&lt;base_unsigned&gt;(range)+1);</span>
<span class="lineNum">     194 </span><span class="lineNoCov">          0 :         if(brange % (static_cast&lt;base_unsigned&gt;(range)+1) == static_cast&lt;base_unsigned&gt;(range)) {</span>
<span class="lineNum">     195 </span><span class="lineNoCov">          0 :           ++bucket_size;</span>
<span class="lineNum">     196 </span>            :         }
<span class="lineNum">     197 </span>            :       } else {
<span class="lineNum">     198 </span>            :         bucket_size = (brange+1) / (static_cast&lt;base_unsigned&gt;(range)+1);
<span class="lineNum">     199 </span>            :       }
<span class="lineNum">     200 </span>            :       for(;;) {
<span class="lineNum">     201 </span>            :         base_unsigned result =
<span class="lineNum">     202 </span><span class="lineNoCov">          0 :           random::detail::subtract&lt;base_result&gt;()(eng(), bmin);</span>
<span class="lineNum">     203 </span><span class="lineNoCov">          0 :         result /= bucket_size;</span>
<span class="lineNum">     204 </span>            :         // result and range are non-negative, and result is possibly larger
<span class="lineNum">     205 </span>            :         // than range, so the cast is safe
<span class="lineNum">     206 </span><span class="lineNoCov">          0 :         if(result &lt;= static_cast&lt;base_unsigned&gt;(range))</span>
<span class="lineNum">     207 </span>            :           return random::detail::add&lt;base_unsigned, result_type&gt;()(result, min_value);
<span class="lineNum">     208 </span>            :       }
<span class="lineNum">     209 </span>            :     }
<span class="lineNum">     210 </span>            : }
<span class="lineNum">     211 </span>            : 
<span class="lineNum">     212 </span>            : #ifdef BOOST_MSVC
<span class="lineNum">     213 </span>            : #pragma warning(pop)
<span class="lineNum">     214 </span>            : #endif
<span class="lineNum">     215 </span>            : 
<span class="lineNum">     216 </span>            : template&lt;class Engine, class T&gt;
<span class="lineNum">     217 </span>            : inline T generate_uniform_int(
<span class="lineNum">     218 </span>            :     Engine&amp; eng, T min_value, T max_value,
<span class="lineNum">     219 </span>            :     boost::mpl::false_ /** is_integral&lt;Engine::result_type&gt; */)
<span class="lineNum">     220 </span>            : {
<span class="lineNum">     221 </span>            :     uniform_int_float&lt;Engine&gt; wrapper(eng);
<span class="lineNum">     222 </span>            :     return generate_uniform_int(wrapper, min_value, max_value, boost::mpl::true_());
<span class="lineNum">     223 </span>            : }
<span class="lineNum">     224 </span>            : 
<span class="lineNum">     225 </span>            : template&lt;class Engine, class T&gt;
<span class="lineNum">     226 </span>            : inline T generate_uniform_int(Engine&amp; eng, T min_value, T max_value)
<span class="lineNum">     227 </span>            : {
<span class="lineNum">     228 </span>            :     typedef typename Engine::result_type base_result;
<span class="lineNum">     229 </span>            :     return generate_uniform_int(eng, min_value, max_value,
<span class="lineNum">     230 </span><span class="lineNoCov">          0 :         boost::is_integral&lt;base_result&gt;());</span>
<span class="lineNum">     231 </span>            : }
<span class="lineNum">     232 </span>            : 
<span class="lineNum">     233 </span>            : }
<span class="lineNum">     234 </span>            : 
<span class="lineNum">     235 </span>            : /**
<span class="lineNum">     236 </span>            :  * The class template uniform_int_distribution models a \random_distribution.
<span class="lineNum">     237 </span>            :  * On each invocation, it returns a random integer value uniformly
<span class="lineNum">     238 </span>            :  * distributed in the set of integers {min, min+1, min+2, ..., max}.
<span class="lineNum">     239 </span>            :  *
<span class="lineNum">     240 </span>            :  * The template parameter IntType shall denote an integer-like value type.
<span class="lineNum">     241 </span>            :  */
<span class="lineNum">     242 </span>            : template&lt;class IntType = int&gt;
<span class="lineNum">     243 </span>            : class uniform_int_distribution
<span class="lineNum">     244 </span>            : {
<span class="lineNum">     245 </span>            : public:
<span class="lineNum">     246 </span>            :     typedef IntType input_type;
<span class="lineNum">     247 </span>            :     typedef IntType result_type;
<span class="lineNum">     248 </span>            : 
<span class="lineNum">     249 </span>            :     class param_type
<span class="lineNum">     250 </span>            :     {
<span class="lineNum">     251 </span>            :     public:
<span class="lineNum">     252 </span>            : 
<span class="lineNum">     253 </span>            :         typedef uniform_int_distribution distribution_type;
<span class="lineNum">     254 </span>            : 
<span class="lineNum">     255 </span>            :         /**
<span class="lineNum">     256 </span>            :          * Constructs the parameters of a uniform_int_distribution.
<span class="lineNum">     257 </span>            :          *
<span class="lineNum">     258 </span>            :          * Requires min &lt;= max
<span class="lineNum">     259 </span>            :          */
<span class="lineNum">     260 </span>            :         explicit param_type(
<span class="lineNum">     261 </span>            :             IntType min_arg = 0,
<span class="lineNum">     262 </span>            :             IntType max_arg = (std::numeric_limits&lt;IntType&gt;::max)())
<span class="lineNum">     263 </span>            :           : _min(min_arg), _max(max_arg)
<span class="lineNum">     264 </span>            :         {
<span class="lineNum">     265 </span>            :             BOOST_ASSERT(_min &lt;= _max);
<span class="lineNum">     266 </span>            :         }
<span class="lineNum">     267 </span>            : 
<span class="lineNum">     268 </span>            :         /** Returns the minimum value of the distribution. */
<span class="lineNum">     269 </span>            :         IntType a() const { return _min; }
<span class="lineNum">     270 </span>            :         /** Returns the maximum value of the distribution. */
<span class="lineNum">     271 </span>            :         IntType b() const { return _max; }
<span class="lineNum">     272 </span>            : 
<span class="lineNum">     273 </span>            :         /** Writes the parameters to a @c std::ostream. */
<span class="lineNum">     274 </span>            :         BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, param_type, parm)
<span class="lineNum">     275 </span>            :         {
<span class="lineNum">     276 </span>            :             os &lt;&lt; parm._min &lt;&lt; &quot; &quot; &lt;&lt; parm._max;
<span class="lineNum">     277 </span>            :             return os;
<span class="lineNum">     278 </span>            :         }
<span class="lineNum">     279 </span>            : 
<span class="lineNum">     280 </span>            :         /** Reads the parameters from a @c std::istream. */
<span class="lineNum">     281 </span>            :         BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, param_type, parm)
<span class="lineNum">     282 </span>            :         {
<span class="lineNum">     283 </span>            :             IntType min_in, max_in;
<span class="lineNum">     284 </span>            :             if(is &gt;&gt; min_in &gt;&gt; std::ws &gt;&gt; max_in) {
<span class="lineNum">     285 </span>            :                 if(min_in &lt;= max_in) {
<span class="lineNum">     286 </span>            :                     parm._min = min_in;
<span class="lineNum">     287 </span>            :                     parm._max = max_in;
<span class="lineNum">     288 </span>            :                 } else {
<span class="lineNum">     289 </span>            :                     is.setstate(std::ios_base::failbit);
<span class="lineNum">     290 </span>            :                 }
<span class="lineNum">     291 </span>            :             }
<span class="lineNum">     292 </span>            :             return is;
<span class="lineNum">     293 </span>            :         }
<span class="lineNum">     294 </span>            : 
<span class="lineNum">     295 </span>            :         /** Returns true if the two sets of parameters are equal. */
<span class="lineNum">     296 </span>            :         BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(param_type, lhs, rhs)
<span class="lineNum">     297 </span>            :         { return lhs._min == rhs._min &amp;&amp; lhs._max == rhs._max; }
<span class="lineNum">     298 </span>            : 
<span class="lineNum">     299 </span>            :         /** Returns true if the two sets of parameters are different. */
<span class="lineNum">     300 </span>            :         BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(param_type)
<span class="lineNum">     301 </span>            : 
<span class="lineNum">     302 </span>            :     private:
<span class="lineNum">     303 </span>            : 
<span class="lineNum">     304 </span>            :         IntType _min;
<span class="lineNum">     305 </span>            :         IntType _max;
<span class="lineNum">     306 </span>            :     };
<span class="lineNum">     307 </span>            : 
<span class="lineNum">     308 </span>            :     /**
<span class="lineNum">     309 </span>            :      * Constructs a uniform_int_distribution. @c min and @c max are
<span class="lineNum">     310 </span>            :      * the parameters of the distribution.
<span class="lineNum">     311 </span>            :      *
<span class="lineNum">     312 </span>            :      * Requires: min &lt;= max
<span class="lineNum">     313 </span>            :      */
<span class="lineNum">     314 </span>            :     explicit uniform_int_distribution(
<span class="lineNum">     315 </span>            :         IntType min_arg = 0,
<span class="lineNum">     316 </span>            :         IntType max_arg = (std::numeric_limits&lt;IntType&gt;::max)())
<span class="lineNum">     317 </span>            :       : _min(min_arg), _max(max_arg)
<span class="lineNum">     318 </span>            :     {
<span class="lineNum">     319 </span>            :         BOOST_ASSERT(min_arg &lt;= max_arg);
<span class="lineNum">     320 </span>            :     }
<span class="lineNum">     321 </span>            :     /** Constructs a uniform_int_distribution from its parameters. */
<span class="lineNum">     322 </span>            :     explicit uniform_int_distribution(const param_type&amp; parm)
<span class="lineNum">     323 </span>            :       : _min(parm.a()), _max(parm.b()) {}
<span class="lineNum">     324 </span>            : 
<span class="lineNum">     325 </span>            :     /**  Returns the minimum value of the distribution */
<span class="lineNum">     326 </span>            :     IntType min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; }
<span class="lineNum">     327 </span>            :     /**  Returns the maximum value of the distribution */
<span class="lineNum">     328 </span>            :     IntType max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; }
<span class="lineNum">     329 </span>            : 
<span class="lineNum">     330 </span>            :     /**  Returns the minimum value of the distribution */
<span class="lineNum">     331 </span>            :     IntType a() const { return _min; }
<span class="lineNum">     332 </span>            :     /**  Returns the maximum value of the distribution */
<span class="lineNum">     333 </span>            :     IntType b() const { return _max; }
<span class="lineNum">     334 </span>            : 
<span class="lineNum">     335 </span>            :     /** Returns the parameters of the distribution. */
<span class="lineNum">     336 </span>            :     param_type param() const { return param_type(_min, _max); }
<span class="lineNum">     337 </span>            :     /** Sets the parameters of the distribution. */
<span class="lineNum">     338 </span>            :     void param(const param_type&amp; parm)
<span class="lineNum">     339 </span>            :     {
<span class="lineNum">     340 </span>            :         _min = parm.a();
<span class="lineNum">     341 </span>            :         _max = parm.b();
<span class="lineNum">     342 </span>            :     }
<span class="lineNum">     343 </span>            : 
<span class="lineNum">     344 </span>            :     /**
<span class="lineNum">     345 </span>            :      * Effects: Subsequent uses of the distribution do not depend
<span class="lineNum">     346 </span>            :      * on values produced by any engine prior to invoking reset.
<span class="lineNum">     347 </span>            :      */
<span class="lineNum">     348 </span>            :     void reset() { }
<span class="lineNum">     349 </span>            : 
<span class="lineNum">     350 </span>            :     /** Returns an integer uniformly distributed in the range [min, max]. */
<span class="lineNum">     351 </span>            :     template&lt;class Engine&gt;
<span class="lineNum">     352 </span>            :     result_type operator()(Engine&amp; eng) const
<span class="lineNum">     353 </span>            :     { return detail::generate_uniform_int(eng, _min, _max); }
<span class="lineNum">     354 </span>            : 
<span class="lineNum">     355 </span>            :     /**
<span class="lineNum">     356 </span>            :      * Returns an integer uniformly distributed in the range
<span class="lineNum">     357 </span>            :      * [param.a(), param.b()].
<span class="lineNum">     358 </span>            :      */
<span class="lineNum">     359 </span>            :     template&lt;class Engine&gt;
<span class="lineNum">     360 </span>            :     result_type operator()(Engine&amp; eng, const param_type&amp; parm) const
<span class="lineNum">     361 </span>            :     { return detail::generate_uniform_int(eng, parm.a(), parm.b()); }
<span class="lineNum">     362 </span>            : 
<span class="lineNum">     363 </span>            :     /** Writes the distribution to a @c std::ostream. */
<span class="lineNum">     364 </span>            :     BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, uniform_int_distribution, ud)
<span class="lineNum">     365 </span>            :     {
<span class="lineNum">     366 </span>            :         os &lt;&lt; ud.param();
<span class="lineNum">     367 </span>            :         return os;
<span class="lineNum">     368 </span>            :     }
<span class="lineNum">     369 </span>            : 
<span class="lineNum">     370 </span>            :     /** Reads the distribution from a @c std::istream. */
<span class="lineNum">     371 </span>            :     BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, uniform_int_distribution, ud)
<span class="lineNum">     372 </span>            :     {
<span class="lineNum">     373 </span>            :         param_type parm;
<span class="lineNum">     374 </span>            :         if(is &gt;&gt; parm) {
<span class="lineNum">     375 </span>            :             ud.param(parm);
<span class="lineNum">     376 </span>            :         }
<span class="lineNum">     377 </span>            :         return is;
<span class="lineNum">     378 </span>            :     }
<span class="lineNum">     379 </span>            : 
<span class="lineNum">     380 </span>            :     /**
<span class="lineNum">     381 </span>            :      * Returns true if the two distributions will produce identical sequences
<span class="lineNum">     382 </span>            :      * of values given equal generators.
<span class="lineNum">     383 </span>            :      */
<span class="lineNum">     384 </span>            :     BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(uniform_int_distribution, lhs, rhs)
<span class="lineNum">     385 </span>            :     { return lhs._min == rhs._min &amp;&amp; lhs._max == rhs._max; }
<span class="lineNum">     386 </span>            :     
<span class="lineNum">     387 </span>            :     /**
<span class="lineNum">     388 </span>            :      * Returns true if the two distributions may produce different sequences
<span class="lineNum">     389 </span>            :      * of values given equal generators.
<span class="lineNum">     390 </span>            :      */
<span class="lineNum">     391 </span>            :     BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(uniform_int_distribution)
<span class="lineNum">     392 </span>            : 
<span class="lineNum">     393 </span>            : private:
<span class="lineNum">     394 </span>            :     IntType _min;
<span class="lineNum">     395 </span>            :     IntType _max;
<span class="lineNum">     396 </span>            : };
<span class="lineNum">     397 </span>            : 
<span class="lineNum">     398 </span>            : } // namespace random
<span class="lineNum">     399 </span>            : } // namespace boost
<span class="lineNum">     400 </span>            : 
<span class="lineNum">     401 </span>            : #endif // BOOST_RANDOM_UNIFORM_INT_HPP
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
